<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: Blinky</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a> ]
    </div>

    <h1>Coverage Summary for Class: Blinky (nl.tudelft.jpacman.npc.ghost)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">Blinky</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 3)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 12)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.npc.ghost;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.util.List;
        <i>4</i>&nbsp;import java.util.Map;
        <i>5</i>&nbsp;import java.util.Optional;
        <i>6</i>&nbsp;
        <i>7</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>8</i>&nbsp;import nl.tudelft.jpacman.board.Square;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>10</i>&nbsp;import nl.tudelft.jpacman.level.Player;
        <i>11</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
        <i>12</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
        <i>13</i>&nbsp;
        <i>14</i>&nbsp;/**
        <i>15</i>&nbsp; * &lt;p&gt;
        <i>16</i>&nbsp; * An implementation of the classic Pac-Man ghost Shadow.
        <i>17</i>&nbsp; * &lt;/p&gt;
        <i>18</i>&nbsp; * &lt;p&gt;
        <i>19</i>&nbsp; * Nickname: Blinky. As his name implies, Shadow is usually a constant shadow on
        <i>20</i>&nbsp; * Pac-Man&#39;s tail. When he&#39;s not patrolling the top-right corner of the maze,
        <i>21</i>&nbsp; * Shadow tries to find the quickest route to Pac-Man&#39;s position. Despite the
        <i>22</i>&nbsp; * fact that Pinky&#39;s real name is Speedy, Shadow is actually the fastest of the
        <i>23</i>&nbsp; * ghosts because of when there are only a few pellets left, Blinky drastically
        <i>24</i>&nbsp; * speeds up, which can make him quite deadly. In the original Japanese version,
        <i>25</i>&nbsp; * his name is Oikake/Akabei.
        <i>26</i>&nbsp; * &lt;/p&gt;
        <i>27</i>&nbsp; * &lt;p&gt;
        <i>28</i>&nbsp; * &lt;b&gt;AI:&lt;/b&gt; When the ghosts are not patrolling in their home corners (Blinky:
        <i>29</i>&nbsp; * top-right, Pinky: top-left, Inky: bottom-right, Clyde: bottom-left), Blinky
        <i>30</i>&nbsp; * will attempt to shorten the distance between Pac-Man and himself. If he has
        <i>31</i>&nbsp; * to choose between shortening the horizontal or vertical distance, he will
        <i>32</i>&nbsp; * choose to shorten whichever is greatest. For example, if Pac-Man is four grid
        <i>33</i>&nbsp; * spaces to the left, and seven grid spaces above Blinky, he&#39;ll try to move up
        <i>34</i>&nbsp; * towards Pac-Man before he moves to the left.
        <i>35</i>&nbsp; * &lt;/p&gt;
        <i>36</i>&nbsp; * &lt;p&gt;
        <i>37</i>&nbsp; * Source: http://strategywiki.org/wiki/Pac-Man/Getting_Started
        <i>38</i>&nbsp; * &lt;/p&gt;
        <i>39</i>&nbsp; *
        <i>40</i>&nbsp; * @author Jeroen Roosen
        <i>41</i>&nbsp; *
        <i>42</i>&nbsp; */
        <b class="nc"><i>43</i>&nbsp;public class Blinky extends Ghost {</b>
        <i>44</i>&nbsp;
        <i>45</i>&nbsp; /**
        <i>46</i>&nbsp; * The variation in intervals, this makes the ghosts look more dynamic and
        <i>47</i>&nbsp; * less predictable.
        <i>48</i>&nbsp; */
        <i>49</i>&nbsp; private static final int INTERVAL_VARIATION = 50;
        <i>50</i>&nbsp;
        <i>51</i>&nbsp; /**
        <i>52</i>&nbsp; * The base movement interval.
        <i>53</i>&nbsp; */
        <i>54</i>&nbsp; private static final int MOVE_INTERVAL = 250;
        <i>55</i>&nbsp;
        <i>56</i>&nbsp; /**
        <i>57</i>&nbsp; * Creates a new &quot;Blinky&quot;, a.k.a. &quot;Shadow&quot;.
        <i>58</i>&nbsp; *
        <i>59</i>&nbsp; * @param spriteMap
        <i>60</i>&nbsp; * The sprites for this ghost.
        <i>61</i>&nbsp; */
        <i>62</i>&nbsp; // TODO Blinky should speed up when there are a few pellets left, but he
        <i>63</i>&nbsp; // has no way to find out how many there are.
        <i>64</i>&nbsp; public Blinky(Map&lt;Direction, Sprite&gt; spriteMap) {
        <b class="nc"><i>65</i>&nbsp; super(spriteMap, MOVE_INTERVAL, INTERVAL_VARIATION);</b>
        <i>66</i>&nbsp; }
        <i>67</i>&nbsp;
        <i>68</i>&nbsp; /**
        <i>69</i>&nbsp; * {@inheritDoc}
        <i>70</i>&nbsp; *
        <i>71</i>&nbsp; * &lt;p&gt;
        <i>72</i>&nbsp; * When the ghosts are not patrolling in their home corners (Blinky:
        <i>73</i>&nbsp; * top-right, Pinky: top-left, Inky: bottom-right, Clyde: bottom-left),
        <i>74</i>&nbsp; * Blinky will attempt to shorten the distance between Pac-Man and himself.
        <i>75</i>&nbsp; * If he has to choose between shortening the horizontal or vertical
        <i>76</i>&nbsp; * distance, he will choose to shorten whichever is greatest. For example,
        <i>77</i>&nbsp; * if Pac-Man is four grid spaces to the left, and seven grid spaces above
        <i>78</i>&nbsp; * Blinky, he&#39;ll try to move up towards Pac-Man before he moves to the left.
        <i>79</i>&nbsp; * &lt;/p&gt;
        <i>80</i>&nbsp; */
        <i>81</i>&nbsp; @Override
        <i>82</i>&nbsp; public Optional&lt;Direction&gt; nextAiMove() {
        <b class="nc"><i>83</i>&nbsp; assert hasSquare();</b>
        <i>84</i>&nbsp;
        <i>85</i>&nbsp; // TODO Blinky should patrol his corner every once in a while
        <i>86</i>&nbsp; // TODO Implement his actual behaviour instead of simply chasing.
        <b class="nc"><i>87</i>&nbsp; Unit nearest = Navigation.findNearest(Player.class, getSquare());</b>
        <b class="nc"><i>88</i>&nbsp; if (nearest == null) {</b>
        <b class="nc"><i>89</i>&nbsp; return Optional.empty();</b>
        <i>90</i>&nbsp; }
        <b class="nc"><i>91</i>&nbsp; assert nearest.hasSquare();</b>
        <b class="nc"><i>92</i>&nbsp; Square target = nearest.getSquare();</b>
        <i>93</i>&nbsp;
        <b class="nc"><i>94</i>&nbsp; List&lt;Direction&gt; path = Navigation.shortestPath(getSquare(), target,
            this);</b>
        <b class="nc"><i>95</i>&nbsp; if (path != null &amp;&amp; !path.isEmpty()) {</b>
        <b class="nc"><i>96</i>&nbsp; return Optional.ofNullable(path.get(0));</b>
        <i>97</i>&nbsp; }
        <b class="nc"><i>98</i>&nbsp; return Optional.empty();</b>
        <i>99</i>&nbsp; }
        <i>100</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
